<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Level_mdl extends CI_Model {

	const TABLE = 'level';

    public function select(){
        return $this->db->get(self::TABLE)->result_array();
    }

    public function get_one(){
        return $this->db->get(self::TABLE)->row_array();
    }

    //统计
    public function get_count(){
        return $this->db->count_all_results(self::TABLE);
    }

    //添加
    public function create($data){
        return $this->db->insert(self::TABLE,$data);
    }
    //修改
    public function update($data){
        return $this->db->update(self::TABLE,$data);
    }
    //删除
    public function delete(){
        return $this->update($data);
    }

    //查询最高层级
    public function get_max(){
    	$this->db->select_max('hierarchy');
    	return $this->db->get(self::TABLE)->row_array();
    }

    //组装数据
    public function reset($list){
    	//查询单笔价格
    	$this->load->model('project_mdl');
    	$this->db->where('id',1);
    	$res = $this->project_mdl->get_one();

    	foreach($list as $k => $v){
    		if(isset($v['max'])){
    			$list[$k]['max_num'] = $res['price'] * $v['max'];
    		}

    		if(isset($v['min'])){
    			$list[$k]['min_num'] = $res['price'] * $v['min'];
    		}
    	}

    	return $list;
    }

}

/* End of file Level_mdl.php */
/* Location: ./application/models/Level_mdl.php */